package org.example.controller;


import org.example.service.ProductService;
import org.example.util.JsonData;
import org.example.vo.ProductVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 谢超
 * @since 2024-03-21
 */
@RestController
@RequestMapping("/api/product/v1")
public class ProductController {

    @Resource
    private ProductService productService;

    /**
     * 查看商品列表
     * @return
     */
    @GetMapping("list")
    public JsonData getList(){
        List<ProductVO> productVOList = productService.getList();
        return JsonData.buildSuccess(productVOList);
    }

    /**
     * 基于id查看某个商品
     * @param productId
     * @return
     */
    @GetMapping("detail/{product_id}")
    private JsonData getDetail(@PathVariable("product_id") long productId) {
        ProductVO productVO = productService.getDetail(productId);
        return JsonData.buildSuccess(productVO);
    }
}

